package com.netty.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketTest {
	private static final int portNumber = 8080;

	public static void socketService() throws IOException {
		// 创建一个serverSocket 监听指定端口
		ServerSocket serverSocket = new ServerSocket();
		// 对accept() 方法的调用将被阻塞,直到一个连接建立
		Socket clientSocket = serverSocket.accept();
		// 这些流对象都派生于该套接字的流对象
		BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
		PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
		String request, response;
		while ((request = in.readLine()) != null) {
			if ("Done".equals(request)) {
				break;
			}
			response = processRequest(request);
			out.println(response);
		}
	}

	public static void channelService() {

	}

	public static String processRequest(String request) {
		return "response";
	}


	public static void main(String[] args) throws IOException {
		socketService();
	}

}
